package com.rljk.controller.backend;/**
 * Created by mac on 2018/7/11.
 */

import com.rljk.common.controller.BaseController;
import com.rljk.common.result.CodeMsg;
import com.rljk.common.result.Result;
import com.rljk.domain.common.PageData;
import com.rljk.service.CategoryManager;
import com.rljk.utils.AppUtil;
import com.rljk.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName CategoryController
 * @Description 分类控制层
 * @Author zhang
 * @Date 2018/7/11 10:25
 */
@RestController
@RequestMapping("/Category")
@Slf4j
public class CategoryController extends BaseController {

    @Resource(name = "categoryService")
    private CategoryManager categoryService;


    /*
     * @Author zhang
     * @Description  后台添加分类
     * @Date 2018/7/11 10:33
     * @Param []
     * @return java.lang.Object
     **/
    @RequestMapping(value="/add")
    public Object addCategory(){
        log.info("后台添加分类");
        PageData pd = new PageData();
        pd = this.getPageData();
        try{
            if(Tools.checkKey("ADDCATEGORY", pd.getString("FKEY"))){	//检验请求key值是否合法
                if(AppUtil.checkParam("addCategory", pd)){	//检查参数
                    log.info("请求参数："+pd.toString());
                    pd.put("CATEGORY_ID",this.getSnowId());
                    categoryService.save(pd);
                    return Result.success(null);
                }else {
                    return Result.error(CodeMsg.PARAM_LACK);
                }
            }else{
                return Result.error(CodeMsg.FKEY_FAIL);
            }
        }catch (Exception e){
            log.error(e.toString(), e);
            return Result.error(CodeMsg.SERVER_ERROR);
        }
    }

}
